package com.gmall.rabbitmq.producer.controller;

import com.gmall.rabbitmq.config.RabbitMQConfig_WorkQueue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/workqueue")
public class WorkQueueController {

    @Autowired
    RabbitTemplate rabbitTemplate;


    @GetMapping("/produce")
    public String produce(){

        for(int i=0;i<100;i++){
            rabbitTemplate.convertAndSend(
                    RabbitMQConfig_WorkQueue.Exchange_Direct_WorkQueue,
                    RabbitMQConfig_WorkQueue.RoutingKey_WorkQueue
                    ,"helloworld:" + i);
        }

        return "OK";
    }

}
